package com.linhai.mybatis.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.linhai.mybatis.service.IUserService;
import com.linhai.mybatis.service.IEventLogService;

@Controller
@RequestMapping("/")
public class AccountController {
	

	@Resource
	private IUserService userService=null;
	@Resource
	private IEventLogService eventLogService=null;
	
	@RequestMapping("login")
	public String login(){
		return "login";
	}
	
	@RequestMapping("checklogin")
	public String checkLogin(HttpSession session,String _url){
		//这里做验证登录的事
		boolean flag=false;
		if(flag){
			//登录完成后保存登录状态
			session.setAttribute("isLogin", true);
			if(null==_url || "".equals(_url)){
				_url="redirect:/index";
			}
		}else{
			_url="redirect:/login";
		}
		return _url;
	}

	//@ResponseBody
	@RequestMapping("logout")
	public String logout(HttpSession session){
		//session.removeAttribute("isLogin");//退出登录，移除登录状态
		com.linhai.mybatis.model.EventLog eventLog=new com.linhai.mybatis.model.EventLog();
		eventLog.setEventName("退出登入");
		eventLog.setEventDateTime(new java.util.Date());
		eventLog.setEventType("用户操作");
		eventLogService.insertEventLog(eventLog);
		return "redirect:/index";
		
	}
	
}
